package org.duang.handles;

import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.duang.config.Config;
import org.duang.config.InstanceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Handles {

	private static Logger logger = LoggerFactory.getLogger(Handles.class);

	public static void init() {
		InstanceFactory.getHandles().add(0, new InitHandle());
		// 添加ActionHandle，在其它的Handle后
		InstanceFactory.getHandles().add(new ActionHandle());
		InstanceFactory.getHandles().add(new DRLHandle());
		printHandles();
	}

	private static void printHandles() {
		for (IHandle handle : InstanceFactory.getHandles()) {
			logger.warn(handle.getClass().getName() + " start success...");
		}
	}

	public static void execute(String target, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		for (Iterator<IHandle> it = InstanceFactory.getHandles().iterator(); it.hasNext();) {
			it.next().execute(target, request, response);
		}
	}

}
